<?php

namespace App\Http\Requests\Admin\V1;

use Illuminate\Validation\Rule;

class AdminUpdateRequest extends FormRequest
{
    /**
     * @expalin 验证规则
     * @return array
     * @method
     * @author 陈文小超
     * @maxim from专注to执行
     * @time 2021/3/30/14:29
     */
    public function rules()
    {
        return [
            'id'        => ['bail', 'required', 'integer', 'min:1000', 'max:10000', 'exists:admin_users,id'],
            'name'      => ['bail', 'required', 'alpha_num', 'min:2', 'max:20'],
            'nickname'  => ['bail', 'required', 'alpha_num', 'min:2', 'max:20', Rule::unique('admin_users', 'nickname')->ignore(self::input('id'))],
            'username'  => ['bail', 'required', 'alpha_num', 'min:6', 'max:20', Rule::unique('admin_users', 'username')->ignore(self::input('id'))],
            'email'     => ['bail', 'nullable', 'email'],
            'password'  => ['bail', 'required', 'alpha_dash', 'min:6'],
            'role_id'   => ['bail', 'required', 'integer', 'exists:roles,id'],
            'is_enable' => ['bail', 'required', 'boolean'],
        ];
    }

    /**
     * @expalin 自定义错误信息
     * @return array
     * @method
     * @author 陈文小超
     * @maxim from专注to执行
     * @time 2021/3/30/14:29
     */
    public function messages()
    {
        return [
            'id.*'                => trans('admin/v1/request.admin.id'),
            'name.required'       => trans('admin/v1/request.admin.name-required'),
            'name.max'            => trans('admin/v1/request.admin.name-max'),
            'account.required'    => trans('admin/v1/request.admin.account-required'),
            'account.alpha_num'   => trans('admin/v1/request.admin.account-alpha_num'),
            'account.min'         => trans('admin/v1/request.admin.account-min'),
            'account.max'         => trans('admin/v1/request.admin.account-max'),
            'email.email'         => trans('admin/v1/request.admin.email-email'),
            'password.required'   => trans('admin/v1/request.admin.password-required'),
            'password.alpha_dash' => trans('admin/v1/request.admin.password-alpha_dash'),
            'password.min'        => trans('admin/v1/request.admin.password-min'),
            'role_id.required'    => trans('admin/v1/request.admin.role_id-required'),
            'role_id.integer'     => trans('admin/v1/request.admin.role_id-integer'),
            'is_enable.required'  => trans('admin/v1/request.admin.is_enable-required'),
            'is_enable.boolean'   => trans('admin/v1/request.admin.is_enable-boolean'),
        ];
    }
}
